
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<%@taglib prefix="shiro" uri="http://shiro.apache.org/tags" %>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>员工</title>
    <link rel="stylesheet" type="text/css" href="/static/plugins/easyui/themes/material/easyui.css">
    <link rel="stylesheet" type="text/css" href="/static/plugins/easyui/themes/icon.css">
    <script type="text/javascript" src="/static/plugins/easyui/jquery.min.js"></script>
    <script type="text/javascript" src="/static/plugins/easyui/jquery.easyui.min.js"></script>
    <script type="text/javascript" src="/static/plugins/easyui/locale/easyui-lang-zh_CN.js"></script>
    <script>
        $(function () {
            //编辑对话框
            $("#department_dig").dialog({
                width: 400,
                height: 200,
                closed: true,
                cache: false,
                modal: true,
                buttons:'#department_dig_btn'
            })

            $('#department_dg').datagrid({
                url:'/department/query.do',
                fitColumns:true,
                fit:true,
                pagination:true,
                singleSelect:true,
                toolbar:"#department_tb",
                rownumbers:true,
                onClickRow:function (index, row) {

                    if (row.state) {

                        $("#btn_change").linkbutton({iconCls:'icon-no',text:'禁用'})
                    }
                    else{
                        $("#btn_change").linkbutton({iconCls:'icon-ok',text:'启用'})

                    }
                },
                columns:[[
                    {field:'id',title:'编号',width:100},
                    {field:'name',title:'部门名称',width:100},
                    {field:'sn',title:'部门编号',width:100},
                    {field:'state',title:'状态',width:100,formatter: function(value,row,index){
                            if (value){
                                return "启用";
                            } else {
                                return "<span style='color: red'>禁用</span>";
                            }
                        }}

                ]]
            });
        })
        /*提交表单*/
        function submitForm() {
            $('#department_form').form({
                url:'/department/saveOrUpdate.do',

                success:function(data){
                    var data =  $.parseJSON(data);
                    if (data.success) {
                        $.messager.alert('温馨提示','保存成功','info',function () {

                            closeWin();
                            $('#department_dg').datagrid("reload");
                        });
                    }
                    else{
                        $.messager.alert('温馨提示',data.msg);
                        closeWin();

                    }
                }
            });


            $('#department_form').submit();
        }

        function saveUser() {

            $("#department_dig").dialog("setTitle","add");
            $("#department_dig").dialog("open");
        }
        /*编辑*/
        function editUser() {
            var tr = $('#department_dg').datagrid("getSelected");

            if (!tr) {
                //没有选中
                $.messager.alert('温馨提示',"至少选中一条数据");
                return;
            }
            console.log(tr);

            $("#department_dig").dialog("setTitle","editUser");
            $("#department_dig").dialog("open");
            $('#department_form').form("load",tr)
        };
        /*删除*/
        function deleteUser() {
            var tr = $('#department_dg').datagrid("getSelected");
            if (!tr) {
                //没有选中
                $.messager.alert('温馨提示',"至少选中一条数据");
                return;
            }
            $.get("/department/delete.do",{id:tr.id},function (data) {
                if (data.success) {
                    $.messager.alert('温馨提示','删除成功','info',function () {


                        $('#department_dg').datagrid("reload");
                    });
                }
                else{
                    $.messager.alert('温馨提示',data.msg);


                }
            })
        }

        /*离职*/
        function changeUser() {
            var tr = $('#department_dg').datagrid("getSelected");
            if (!tr) {
                //没有选中
                $.messager.alert('温馨提示',"至少选中一条数据");
                return;
            }
            $.get("/department/changeState.do",{id:tr.id},function (data) {
                if (data.success) {
                    $.messager.alert('温馨提示','操作成功','info',function () {


                        $('#department_dg').datagrid("reload");
                    });
                }
                else{
                    $.messager.alert('温馨提示',data.msg);


                }
            })
        }
        /*刷新*/
        function reloadwin() {
            $('#department_dg').datagrid("reload");
        }

        /*关闭对话框*/
        function closeWin() {
            $("#department_dig").dialog("close")
            $('#department_form').form("clear")
        }


    </script>
</head>
<body>
<table id="department_dg"></table>
<div id="department_tb" >
    <a class="easyui-linkbutton" onclick="saveUser()" data-options="iconCls:'icon-add',text:'新增'"></a>
    <a class="easyui-linkbutton" onclick="editUser()" data-options="iconCls:'icon-edit',text:'编辑'"></a>
    <shiro:hasPermission name="department:deleteByPrimaryKey">
    <a class="easyui-linkbutton" onclick="deleteUser()" data-options="iconCls:'icon-remove',text:'删除'"></a>
    </shiro:hasPermission>
    <a id="btn_change" class="easyui-linkbutton" onclick="changeUser()" data-options="iconCls:'icon-no',text:'禁用'"></a>
    <a class="easyui-linkbutton" onclick="reloadwin()" data-options="iconCls:'icon-reload',text:'刷新'"></a>

</div>
<div id="department_dig">
    <form id="department_form" >
        <table align="center" >
            <input type="hidden" name="id">
            <br>
            <br>

            <tr>
                <td>部门名称:</td>
                <td>
                    <input class="easyui-validatebox" type="text" name="name"  />
                </td>
            </tr>

            <tr>
                <td>部门编号:</td>
                <td>
                    <input class="easyui-validatebox" type="text" name="sn"  />
                </td>
            </tr>


        </table>

    </form>
</div>
<!--对话框底部工具栏-->
<div id="department_dig_btn">
    <a class="easyui-linkbutton" onclick="submitForm()" data-options="iconCls:'icon-save',text:'保存'"></a>
    <a class="easyui-linkbutton" onclick="closeWin()" data-options="iconCls:'icon-cancel',text:'取消'"></a>
</div>

</body>
</html>
